# encoding: utf-8
"""
@Time   : 2018/12/21 17:29
@Author : XJH
"""

"""
4.4.1 建立图
"""
import numpy as np
import tensorflow as tf
c = tf.constant(0.0)
g = tf.Graph()
with g.as_default():
    c1 = tf.constant(0.0)
    print(c1.graph)
    print(g)
    print("3", c.graph)
g2 = tf.get_default_graph()
print("4", g2)
tf.reset_default_graph()
g3 = tf.get_default_graph()
print(g3)

"""
4.4.2 获取张量
"""
print(c1.name)
t = g.get_tensor_by_name(name="Const:0")
print(t)

"""
4.4.3 获取节点操作
"""
print("---------4.4.3-------")
a = tf.constant([[1.0, 2.0]])
b = tf.constant([[1.0], [3.0]])
tensor1 = tf.matmul(a, b, name='exampleop')
print(tensor1.name, tensor1)
test = g3.get_tensor_by_name("exampleop:0")
print(test)

print("-------------")
print(tensor1.op.name)
testop = g3.get_operation_by_name("exampleop")
print(testop)

with tf.Session() as sess:
    test = sess.run(test)
    print(test)
    test = tf.get_default_graph().get_tensor_by_name("exampleop:0")
    print(test)

"""
4.4.4 获取元素列表
"""
tt2 = g.get_operations()
print(tt2)

"""
4.4.5 获取对象
"""
tt3 = g.as_graph_element(c1)
print(tt3)